home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / View3DMF NetScape Plugin / CommonSample / MyErrorHandler.c < prev    next >
Encoding:
Text File  |  1996-02-29  |  14.8 KB  |  367 lines  |  [TEXT/MPCC]

  1. // Quickdraw 3D sample code
  2. //
  3. // Nick Thompson, AppleLink: DEVSUPPORT (devsupport@applelink.apple.com)
  4. //
  5. // ©1994-5 Apple Computer Inc., All Rights Reserved
  6.  
  7. #include <Dialogs.h>
  8. #include <Memory.h>
  9. #include <SegLoad.h>
  10. #include <TextUtils.h>
  11.  
  12. #include "QD3D.h"
  13. #include "QD3DErrors.h"
  14.  
  15. #include "MyErrorHandler.h"
  16.  
  17. //---------------------------------------------------------------------------
  18.  
  19. const int kErrorHandlerAlertID = 21032 ;            // ID of the alert resource
  20.  
  21. //---------------------------------------------------------------------------
  22.  
  23. // THIS ENUM MUST MATCH THE STRUCT BELOW
  24. enum {
  25.     kWarningString,
  26.     kErrorString,
  27.     kFirstErrorString,
  28.     kLastErrorString,
  29.     kSpaceString,
  30.     kOpenParen,
  31.     kCloseParen,
  32.     kUnknownErrorString
  33. } ;
  34.  
  35.  
  36. // use these to construct intelligable messages
  37. static struct {
  38.     Str255        errorString ;
  39. } stringTable[] = {
  40.     "\pQuickDraw 3D warning.\r\r", 
  41.     "\pQuickDraw 3D Error.\r\r",
  42.     "\p\rFirst Error: ",
  43.     "\p\rLast Error: "
  44.     "\p ",
  45.     "\p(",
  46.     "\p)",
  47.     "\p\rUnknown Message"
  48. } ;
  49.  
  50.  
  51. //---------------------------------------------------------------------------
  52.  
  53.  
  54. /*
  55.     To generate these tables, copy/paste the error codes from QD3DErrors.h
  56.     and use this regexp:
  57.     
  58.     Find:        kQ3Error([0-9A-z]*),
  59.     Replace:    kQ3Error\1, "\\pkQ3Error\1",
  60.     
  61.     Find:        kQ3Warning([0-9A-z]*),
  62.     Replace:    kQ3Warning\1, "\\pkQ3Warning\1",
  63.     
  64.     Find:        kQ3Notice([0-9A-z]*),
  65.     Replace:    kQ3Notice\1, "\\pkQ3Notice\1",
  66.     
  67. */
  68.  
  69.  
  70. // define a table for all of the QuickDraw 3D error codes
  71. struct {
  72.     TQ3Warning    theWarning ;
  73.     Str255        theString ;
  74. } warningTable[] = {
  75.     /* General System */
  76.     kQ3WarningInternalException, "\pkQ3WarningInternalException",    
  77.     /* Object Warnings */
  78.     kQ3WarningNoObjectSupportForDuplicateMethod, "\pkQ3WarningNoObjectSupportForDuplicateMethod",
  79.     kQ3WarningNoObjectSupportForDrawMethod, "\pkQ3WarningNoObjectSupportForDrawMethod",
  80.     kQ3WarningNoObjectSupportForWriteMethod, "\pkQ3WarningNoObjectSupportForWriteMethod",
  81.     kQ3WarningNoObjectSupportForReadMethod, "\pkQ3WarningNoObjectSupportForReadMethod",
  82.     kQ3WarningUnknownElementType, "\pkQ3WarningUnknownElementType",
  83.     kQ3WarningTypeAndMethodAlreadyDefined, "\pkQ3WarningTypeAndMethodAlreadyDefined",
  84.     kQ3WarningTypeIsOutOfRange, "\pkQ3WarningTypeIsOutOfRange",
  85.     kQ3WarningTypeHasNotBeenRegistered, "\pkQ3WarningTypeHasNotBeenRegistered",
  86.     /* Parameter Warnings */
  87.     kQ3WarningVector3DNotUnitLength, "\pkQ3WarningVector3DNotUnitLength",
  88.     /* IO Warnings */
  89.     kQ3WarningInvalidSubObjectForObject, "\pkQ3WarningInvalidSubObjectForObject",
  90.     kQ3WarningInvalidHexString, "\pkQ3WarningInvalidHexString",
  91.     kQ3WarningUnknownObject, "\pkQ3WarningUnknownObject",
  92.     kQ3WarningInvalidMetafileObject, "\pkQ3WarningInvalidMetafileObject",
  93.     kQ3WarningUnmatchedBeginGroup, "\pkQ3WarningUnmatchedBeginGroup",
  94.     kQ3WarningUnmatchedEndGroup, "\pkQ3WarningUnmatchedEndGroup",
  95.     kQ3WarningInvalidTableOfContents, "\pkQ3WarningInvalidTableOfContents",
  96.     kQ3WarningUnresolvableReference, "\pkQ3WarningUnresolvableReference",
  97.     kQ3WarningNoAttachMethod, "\pkQ3WarningNoAttachMethod",
  98.     kQ3WarningInconsistentData, "\pkQ3WarningInconsistentData",
  99.     kQ3WarningReadLessThanSize, "\pkQ3WarningReadLessThanSize",
  100.     kQ3WarningFilePointerResolutionFailed, "\pkQ3WarningFilePointerResolutionFailed",
  101.     kQ3WarningFilePointerRedefined, "\pkQ3WarningFilePointerRedefined",
  102.     kQ3WarningStringExceedsMaximumLength, "\pkQ3WarningStringExceedsMaximumLength",
  103.     /* Memory Warnings */
  104.     kQ3WarningLowMemory, "\pkQ3WarningLowMemory",
  105.     kQ3WarningPossibleMemoryLeak, "\pkQ3WarningPossibleMemoryLeak",
  106.     /* View Warnings */
  107.     kQ3WarningViewTraversalInProgress, "\pkQ3WarningViewTraversalInProgress",
  108.     kQ3WarningNonInvertibleMatrix, "\pkQ3WarningNonInvertibleMatrix",
  109.     /* Quaternion Warning */
  110.     kQ3WarningQuaternionEntriesAreZero, "\pkQ3WarningQuaternionEntriesAreZero",
  111.     /* Renderer Warning */
  112.     kQ3WarningFunctionalityNotSupported, "\pkQ3WarningFunctionalityNotSupported",
  113.     /* DrawContext Warning */
  114.     kQ3WarningInvalidPaneDimensions, "\pkQ3WarningInvalidPaneDimensions",
  115.     /* Pick Warning */
  116.     kQ3WarningPickParamOutside, "\pkQ3WarningPickParamOutside",
  117.     /* Scale Warnings */
  118.     kQ3WarningScaleEntriesAllZero, "\pkQ3WarningScaleEntriesAllZero",
  119.     kQ3WarningScaleContainsNegativeEntries, "\pkQ3WarningScaleContainsNegativeEntries",
  120.     /* Generic Warnings */
  121.     kQ3WarningParameterOutOfRange, "\pkQ3WarningParameterOutOfRange",
  122. } ;
  123.  
  124.  
  125. struct {
  126.     TQ3Error    theError ;
  127.     Str255        theString ;
  128. } errorTable[] = {
  129.     /* Fatal Errors */
  130.     kQ3ErrorInternalError, "\pkQ3ErrorInternalError",
  131.     kQ3ErrorNoRecovery, "\pkQ3ErrorNoRecovery",                    /* TODO: This is not used correctly */
  132.     kQ3ErrorLastFatalError, "\pkQ3ErrorLastFatalError",
  133.     /* System Errors */
  134.     kQ3ErrorNotInitialized, "\pkQ3ErrorNotInitialized",
  135.     kQ3ErrorAlreadyInitialized, "\pkQ3ErrorAlreadyInitialized",
  136.     kQ3ErrorUnimplemented, "\pkQ3ErrorUnimplemented",
  137.     kQ3ErrorRegistrationFailed, "\pkQ3ErrorRegistrationFailed",
  138.     /* OS Errors */
  139.     kQ3ErrorUnixError, "\pkQ3ErrorUnixError",
  140.     kQ3ErrorMacintoshError, "\pkQ3ErrorMacintoshError",
  141.     kQ3ErrorX11Error, "\pkQ3ErrorX11Error",
  142.     /* Memory Errors */
  143.     kQ3ErrorMemoryLeak, "\pkQ3ErrorMemoryLeak",
  144.     kQ3ErrorOutOfMemory, "\pkQ3ErrorOutOfMemory",
  145.     /* Parameter errors */
  146.     kQ3ErrorNULLParameter, "\pkQ3ErrorNULLParameter",
  147.     kQ3ErrorParameterOutOfRange, "\pkQ3ErrorParameterOutOfRange",
  148.     kQ3ErrorInvalidParameter, "\pkQ3ErrorInvalidParameter",            /* TODO: Make this more specific */
  149.     kQ3ErrorInvalidData, "\pkQ3ErrorInvalidData",                /* TODO: Is this used? */
  150.     kQ3ErrorAcceleratorAlreadySet, "\pkQ3ErrorAcceleratorAlreadySet",        /* TODO: Is this used? */
  151.     kQ3ErrorVector3DNotUnitLength, "\pkQ3ErrorVector3DNotUnitLength",
  152.     kQ3ErrorVector3DZeroLength, "\pkQ3ErrorVector3DZeroLength",
  153.     /* Object Errors */
  154.     kQ3ErrorInvalidObject, "\pkQ3ErrorInvalidObject",
  155.     kQ3ErrorInvalidObjectClass, "\pkQ3ErrorInvalidObjectClass",
  156.     kQ3ErrorInvalidObjectType, "\pkQ3ErrorInvalidObjectType",
  157.     kQ3ErrorInvalidObjectName, "\pkQ3ErrorInvalidObjectName",
  158.     kQ3ErrorObjectClassInUse, "\pkQ3ErrorObjectClassInUse",            
  159.     kQ3ErrorAccessRestricted, "\pkQ3ErrorAccessRestricted",
  160.     kQ3ErrorMetaHandlerRequired, "\pkQ3ErrorMetaHandlerRequired",
  161.     kQ3ErrorNeedRequiredMethods, "\pkQ3ErrorNeedRequiredMethods",
  162.     kQ3ErrorNoSubClassType, "\pkQ3ErrorNoSubClassType",
  163.     kQ3ErrorUnknownElementType, "\pkQ3ErrorUnknownElementType",
  164.     kQ3ErrorNotSupported, "\pkQ3ErrorNotSupported",
  165.     /* Extension Errors */
  166.     kQ3ErrorNoExtensionsFolder, "\pkQ3ErrorNoExtensionsFolder",
  167.     kQ3ErrorExtensionError, "\pkQ3ErrorExtensionError",
  168.     kQ3ErrorPrivateExtensionError, "\pkQ3ErrorPrivateExtensionError",
  169.     /* Geometry Errors */
  170.     kQ3ErrorDegenerateGeometry, "\pkQ3ErrorDegenerateGeometry",
  171.     kQ3ErrorGeometryInsufficientNumberOfPoints, "\pkQ3ErrorGeometryInsufficientNumberOfPoints",
  172.     /* IO Errors */
  173.     kQ3ErrorNoStorageSetForFile, "\pkQ3ErrorNoStorageSetForFile",
  174.     kQ3ErrorEndOfFile, "\pkQ3ErrorEndOfFile",
  175.     kQ3ErrorFileCancelled, "\pkQ3ErrorFileCancelled",
  176.     kQ3ErrorInvalidMetafile, "\pkQ3ErrorInvalidMetafile",
  177.      kQ3ErrorInvalidMetafilePrimitive, "\pkQ3ErrorInvalidMetafilePrimitive",
  178.      kQ3ErrorInvalidMetafileLabel, "\pkQ3ErrorInvalidMetafileLabel",
  179.      kQ3ErrorInvalidMetafileObject, "\pkQ3ErrorInvalidMetafileObject",
  180.      kQ3ErrorInvalidMetafileSubObject, "\pkQ3ErrorInvalidMetafileSubObject",
  181.     kQ3ErrorInvalidSubObjectForObject, "\pkQ3ErrorInvalidSubObjectForObject",
  182.     kQ3ErrorUnresolvableReference, "\pkQ3ErrorUnresolvableReference",
  183.     kQ3ErrorUnknownObject, "\pkQ3ErrorUnknownObject",
  184.     kQ3ErrorStorageInUse, "\pkQ3ErrorStorageInUse",
  185.     kQ3ErrorStorageAlreadyOpen, "\pkQ3ErrorStorageAlreadyOpen",
  186.     kQ3ErrorStorageNotOpen, "\pkQ3ErrorStorageNotOpen",
  187.     kQ3ErrorStorageIsOpen, "\pkQ3ErrorStorageIsOpen",
  188.     kQ3ErrorFileAlreadyOpen, "\pkQ3ErrorFileAlreadyOpen",
  189.     kQ3ErrorFileNotOpen, "\pkQ3ErrorFileNotOpen",
  190.     kQ3ErrorFileIsOpen, "\pkQ3ErrorFileIsOpen",
  191.     kQ3ErrorBeginWriteAlreadyCalled, "\pkQ3ErrorBeginWriteAlreadyCalled",
  192.     kQ3ErrorBeginWriteNotCalled, "\pkQ3ErrorBeginWriteNotCalled",
  193.     kQ3ErrorEndWriteNotCalled, "\pkQ3ErrorEndWriteNotCalled",
  194.     kQ3ErrorReadStateInactive, "\pkQ3ErrorReadStateInactive",
  195.     kQ3ErrorStateUnavailable, "\pkQ3ErrorStateUnavailable",
  196.     kQ3ErrorWriteStateInactive, "\pkQ3ErrorWriteStateInactive",
  197.     kQ3ErrorSizeNotLongAligned, "\pkQ3ErrorSizeNotLongAligned",
  198.     kQ3ErrorFileModeRestriction, "\pkQ3ErrorFileModeRestriction",
  199.     kQ3ErrorInvalidHexString, "\pkQ3ErrorInvalidHexString",
  200.     kQ3ErrorWroteMoreThanSize, "\pkQ3ErrorWroteMoreThanSize",
  201.     kQ3ErrorWroteLessThanSize, "\pkQ3ErrorWroteLessThanSize",
  202.     kQ3ErrorReadLessThanSize, "\pkQ3ErrorReadLessThanSize",
  203.     kQ3ErrorReadMoreThanSize, "\pkQ3ErrorReadMoreThanSize",
  204.     kQ3ErrorNoBeginGroup, "\pkQ3ErrorNoBeginGroup",
  205.     kQ3ErrorSizeMismatch, "\pkQ3ErrorSizeMismatch",
  206.     kQ3ErrorStringExceedsMaximumLength, "\pkQ3ErrorStringExceedsMaximumLength",
  207.     kQ3ErrorValueExceedsMaximumSize, "\pkQ3ErrorValueExceedsMaximumSize",
  208.     kQ3ErrorNonUniqueLabel, "\pkQ3ErrorNonUniqueLabel",
  209.     kQ3ErrorEndOfContainer, "\pkQ3ErrorEndOfContainer",
  210.     kQ3ErrorUnmatchedEndGroup, "\pkQ3ErrorUnmatchedEndGroup",
  211.     kQ3ErrorFileVersionExists, "\pkQ3ErrorFileVersionExists",
  212.     /* View errors */
  213.     kQ3ErrorViewNotStarted, "\pkQ3ErrorViewNotStarted",
  214.     kQ3ErrorViewIsStarted, "\pkQ3ErrorViewIsStarted",
  215.     kQ3ErrorRendererNotSet, "\pkQ3ErrorRendererNotSet",
  216.     kQ3ErrorRenderingIsActive, "\pkQ3ErrorRenderingIsActive",
  217.     kQ3ErrorImmediateModeUnderflow, "\pkQ3ErrorImmediateModeUnderflow",
  218.     kQ3ErrorDisplayNotSet, "\pkQ3ErrorDisplayNotSet",
  219.     kQ3ErrorCameraNotSet, "\pkQ3ErrorCameraNotSet",
  220.     kQ3ErrorDrawContextNotSet, "\pkQ3ErrorDrawContextNotSet",
  221.     kQ3ErrorNonInvertibleMatrix, "\pkQ3ErrorNonInvertibleMatrix",
  222.     kQ3ErrorRenderingNotStarted, "\pkQ3ErrorRenderingNotStarted",
  223.     kQ3ErrorPickingNotStarted, "\pkQ3ErrorPickingNotStarted",
  224.     kQ3ErrorBoundsNotStarted, "\pkQ3ErrorBoundsNotStarted",
  225.     kQ3ErrorDataNotAvailable, "\pkQ3ErrorDataNotAvailable",
  226.     kQ3ErrorNothingToPop, "\pkQ3ErrorNothingToPop",
  227.     /* Renderer Errors */
  228.     kQ3ErrorUnknownStudioType, "\pkQ3ErrorUnknownStudioType",            /* TODO Name Change */
  229.     kQ3ErrorAlreadyRendering, "\pkQ3ErrorAlreadyRendering",
  230.     kQ3ErrorStartGroupRange, "\pkQ3ErrorStartGroupRange",
  231.     kQ3ErrorUnsupportedGeometryType, "\pkQ3ErrorUnsupportedGeometryType",
  232.     kQ3ErrorInvalidGeometryType, "\pkQ3ErrorInvalidGeometryType",
  233.     kQ3ErrorUnsupportedFunctionality, "\pkQ3ErrorUnsupportedFunctionality",
  234.     /* Group Errors */
  235.     kQ3ErrorInvalidPositionForGroup, "\pkQ3ErrorInvalidPositionForGroup",
  236.     kQ3ErrorInvalidObjectForGroup, "\pkQ3ErrorInvalidObjectForGroup",
  237.     kQ3ErrorInvalidObjectForPosition, "\pkQ3ErrorInvalidObjectForPosition",
  238.     /* Transform Errors */
  239.     kQ3ErrorScaleOfZero, "\pkQ3ErrorScaleOfZero",                /* Transform errors? */
  240.     /* String Errors */
  241.     kQ3ErrorBadStringType, "\pkQ3ErrorBadStringType",                /* What is this? */
  242.     /* Attribute Errors */
  243.     kQ3ErrorAttributeNotContained, "\pkQ3ErrorAttributeNotContained",        /* What is this? */
  244.     kQ3ErrorAttributeInvalidType, "\pkQ3ErrorAttributeInvalidType",        /* What is this? */
  245.     /* Camera Errors */
  246.     kQ3ErrorInvalidCameraValues, "\pkQ3ErrorInvalidCameraValues",        /* Redundant with kQ3ErrorParameterOutOfRange */
  247.     /* DrawContext Errors */
  248.     kQ3ErrorBadDrawContextType, "\pkQ3ErrorBadDrawContextType",
  249.     kQ3ErrorBadDrawContextFlag, "\pkQ3ErrorBadDrawContextFlag",
  250.     kQ3ErrorBadDrawContext, "\pkQ3ErrorBadDrawContext",
  251.     kQ3ErrorUnsupportedPixelDepth, "\pkQ3ErrorUnsupportedPixelDepth"
  252. } ;
  253.  
  254.  
  255.  
  256.  
  257. static void ConcatenateString( Str255 firstString, Str255 addThis ) ;
  258. static void CopyString( Str255 firstString, Str255 fromThis ) ;
  259. static void PresentErrMsgInDialog( Str255 theError ) ;
  260.  
  261.  
  262. //-------------------------------------------------------------------------------------------
  263. // MyErrorHandler - handle warnings from QuickDraw 3d
  264. void MyErrorHandler( TQ3Error sticky, TQ3Error latest, long refCon )
  265. {
  266.     Str255     myErrorStr ;
  267.     Str255    theWholeString ;
  268.  
  269.     short    stickyIndex = sticky - kQ3ErrorInternalError ;
  270.     short    latestIndex = latest - kQ3ErrorInternalError ;
  271.     
  272.     // if the error is out of range, then just tell us that something
  273.     // "unknown" happened. Otherwise look up the error from the table.
  274.     if( sticky != kQ3ErrorNone && ( sticky < kQ3ErrorInternalError || sticky > kQ3ErrorUnsupportedPixelDepth )) {
  275.         CopyString(    theWholeString, stringTable[kErrorString].errorString  ) ;
  276.         ConcatenateString( theWholeString, stringTable[ kUnknownErrorString ].errorString ) ;
  277.     }
  278.     else {
  279.         
  280.         
  281.         CopyString(    theWholeString, stringTable[ kErrorString ].errorString  ) ;
  282.         
  283.         ConcatenateString( theWholeString, stringTable[ kFirstErrorString ].errorString ) ;
  284.         CopyString(    myErrorStr, errorTable[ stickyIndex ].theString) ;
  285.         ConcatenateString( theWholeString, myErrorStr) ;
  286.         
  287.         ConcatenateString( theWholeString, stringTable[ kLastErrorString ].errorString ) ;
  288.         CopyString(    myErrorStr, errorTable[ stickyIndex ].theString) ;
  289.         ConcatenateString( theWholeString, myErrorStr) ;
  290.         
  291.         
  292.         // and display the error string 
  293.         PresentErrMsgInDialog( theWholeString ) ;        
  294.     }
  295.     
  296.     // clear down the error
  297.     latest = Q3Error_Get( &sticky );
  298.     
  299. }
  300.  
  301.  
  302. //-------------------------------------------------------------------------------------------
  303. // MyErrorHandler - handle warnings from QuickDraw 3d
  304. void MyWarningHandler( TQ3Warning     sticky, TQ3Warning     latest, long refCon )
  305. {
  306.     Str255     myWarningStr ;
  307.     Str255    theWholeString ;
  308.  
  309.     short    stickyIndex = sticky - kQ3WarningInternalException ;
  310.     short    latestIndex = latest - kQ3WarningInternalException ;
  311.     
  312.     // if the error is out of range, then just tell us that something
  313.     // "unknown" happened. Otherwise look up the error from the table.
  314.     if( sticky != kQ3ErrorNone && ( sticky < kQ3WarningInternalException || sticky > kQ3WarningParameterOutOfRange )) {
  315.     
  316.         CopyString(    theWholeString, stringTable[ kWarningString ].errorString  ) ;
  317.         ConcatenateString( theWholeString, stringTable[ kUnknownErrorString ].errorString ) ;
  318.         
  319.     }
  320.     else {
  321.         
  322.         CopyString(    theWholeString, stringTable[ kWarningString ].errorString  ) ;
  323.         
  324.         ConcatenateString( theWholeString, stringTable[ kFirstErrorString ].errorString ) ;
  325.         CopyString(    myWarningStr, warningTable[ stickyIndex ].theString) ;
  326.         ConcatenateString( theWholeString, myWarningStr) ;
  327.         
  328.         ConcatenateString( theWholeString, stringTable[ kLastErrorString ].errorString ) ;
  329.         CopyString(    myWarningStr, warningTable[ stickyIndex ].theString) ;
  330.         ConcatenateString( theWholeString, myWarningStr) ;
  331.         
  332.         // and display the error string 
  333.         PresentErrMsgInDialog( theWholeString ) ;        
  334.     }
  335.     
  336.     // clear down the error
  337.     latest = Q3Warning_Get( &sticky );
  338.     
  339.  
  340. }
  341.  
  342. //------------------------------------------------------------------------
  343. static void ConcatenateString( Str255 firstString, Str255 addThis )
  344. {
  345.     BlockMove( &addThis[1], &firstString[firstString[0]+1], addThis[0] ) ;
  346.     firstString[0] += addThis[0] ;
  347. }
  348.  
  349.  
  350. //------------------------------------------------------------------------
  351. static void CopyString( Str255 firstString, Str255 fromThis )
  352. {
  353.     BlockMove( &fromThis[1], &firstString[1], fromThis[0] ) ;
  354.     firstString[0] = fromThis[0] ;
  355. }
  356.  
  357. //------------------------------------------------------------------------
  358.  
  359. static void PresentErrMsgInDialog( Str255 theError )
  360. {    
  361.     short    itemHit ;
  362.     ParamText( theError, 0L,  0L,  0L ) ;
  363.     itemHit = StopAlert( kErrorHandlerAlertID, nil ) ;
  364.     
  365.     if( itemHit != ok ) 
  366.         ExitToShell() ;
  367. }